package org.nci.platform.workflow.controller;


import gh.priv.general.common.vo.PageResult;
import gh.priv.general.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.nci.platform.workflow.dto.SysListenerPageQuery;
import org.nci.platform.workflow.dto.SysListenerQuery;
import org.nci.platform.workflow.entity.SysListener;
import org.nci.platform.workflow.service.ISysListenerService;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程监听Controller
 *
 * @author Tony
 * @date 2022-12-25
 */
@Tag(name = "流程监听")
@RestController
@RequestMapping("/flowable/listener")
public class SysListenerController
{
    @Resource
    private ISysListenerService sysListenerService;

    /**
     * 查询流程监听分页列表
     */
    @Operation(summary = "查询流程监听分页列表")
    @PostMapping("/page")
    public Result<PageResult<SysListener>> page(@RequestBody SysListenerPageQuery query)
    {
        PageResult<SysListener> page = sysListenerService.page(query);
        return Result.success(page);
    }

    /**
     * 导出流程监听列表
     */
    @Operation(summary = "导出流程监听列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody SysListenerQuery query)
    {
        sysListenerService.export(response,query);
    }

    /**
     * 获取流程监听详细信息
     */
    @Operation(summary = "获取流程监听详细信息")
    @GetMapping(value = "/{id}")
    public Result<SysListener> getInfo(@PathVariable("id") Long id)
    {
        return Result.success(sysListenerService.getById(id));
    }

    /**
     * 新增流程监听
     */
    @Operation(summary = "新增流程监听")
    @PostMapping
    public Result<Boolean> add(@RequestBody SysListener sysListener)
    {
        sysListenerService.save(sysListener);
        return Result.success();
    }

    /**
     * 修改流程监听
     */
    @Operation(summary = "修改流程监听")
    @PutMapping
    public Result<Boolean> edit(@RequestBody SysListener sysListener)
    {
        sysListenerService.updateById(sysListener);
        return Result.success();
    }

    /**
     * 删除流程监听
     */
    @Operation(summary = "删除流程监听")
	@DeleteMapping("/{ids}")
    public Result<Boolean> remove(@PathVariable List<Long> ids)
    {
        sysListenerService.removeByIds(ids);
        return Result.success();
    }
}
